<template>
	<!-- <view class="content" v-if="iphoneis_payment"> -->
		<u-popup :show="show" mode="bottom" :round="20" @close="colseboxe">
			<view class="box textAc">
				<text class="title fw7">{{title}}</text>
				<view class="password_box">
					<u-code-input v-model="password" size='96rpx' :space="0" focus dot @finish='finish'></u-code-input>
				</view>
				<text class="mimi font99 fontS24" @click="$my.go(`/pages/my/set/changePhone?type=3`)">忘记密码?</text>
			</view>
		</u-popup>
	<!-- </view> -->
</template>

<script>
	import CryptoJS from "@/uni_modules/crypto-js";

	export default {
		props: {
			title: {
				default: "输入支付密码"
			},
			show: {
				default: false
			}
		},
		data() {
			return {
				iphoneis_payment: true,
				iv: "",
				password: "",
			}
		},
		// updated() {
		// 	if (this.$my.phone_type == 'ios') {
		// 		this.$my.post('/index/com/get_payment').then(res => {
		// 			if (res.code == 200) {
		// 				this.iphoneis_payment = res.data.is_payment == 1
		// 			}
		// 		})
		// 	}
		// },
		methods: {
			// 加密
			/**
			 * 
			 * 第一个参数word是待加密或者解密的字符串；
			 * 第二个参数keyStr是aes加密需要用到的16位字符串的key；
			 * 第三个参数是初始化向量 iv。
			 */
			colseboxe() {
				this.$emit("isShow", false)
			},
			randomString(len) {
				len = len || 16;
				var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
				var maxPos = $chars.length;
				var pwd = '';
				for (var i = 0; i < len; i++) {
					pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
				}
				return pwd;
			},
			encrypt(word, keyStr, ivStr) {
				const key = CryptoJS.enc.Latin1.parse(keyStr);
				const iv = CryptoJS.enc.Latin1.parse(ivStr);
				const encoded = CryptoJS.AES.encrypt(word, key, {
					iv: iv,
					mode: CryptoJS.mode.CBC,
					adding: CryptoJS.pad.ZeroPadding
				}).toString()
				this.$emit("finish", encoded, this.iv)
				// this.$emit("isShow", false)
				this.password = '';
			},
			finish(e, iv) {
				this.iv = this.randomString();
				this.password = '';
				// this.encrypt(e, "BLiJjLmfNfuQookzT1ifBv3kkwG62set", this.iv)
				this.$emit("finish", e)
			}
		},
	}
</script>

<style lang="scss" scoped>
	.box {
		height: 30vh;
		width: 100%;
		padding: 40rpx;
		box-sizing: border-box;

		.title {
			font-size: 36rpx;
		}

		.mimi {
			float: right;
			margin-right: 40rpx;
			margin-top: 31rpx;
		}

		.password_box {
			width: 100%;
			padding-left: 35rpx;
			box-sizing: border-box;
			margin-top: 100rpx;
		}

		/deep/ .u-code-input__item:nth-of-type(6) {
			border-radius: 0 20rpx 20rpx 0 !important;
		}

		/deep/ .u-code-input__item:nth-of-type(1) {
			border-radius: 20rpx 0 0 20rpx !important;
		}

		// /deep/.u-code-input__input{
		// 	width: none;
		// 	margin:  100rpx auto !important;
		// }
	}
</style>
